package GUI;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import ModelLayer.*;

public class ProductTable extends AbstractTableModel {

	private String[] columnNames = { "ProductNumber", "SerialNumber",
			"SupplierID", "ProductName", "PurchasePrice", "SalesPrice",
			"RentPrice", "CountryOfOrigin", "Fabricant", "Description",
			"CarModel", "ModelYear", "MinStock", "MaxStock", "GearBoxType",
			"GearAmount", "TireType", "TireSize", "GlassHeight", "GlassWidth",
			"GlassTickness", "BrakeDiscType", "LightsType", "ProductType" };
	
	private ArrayList<Product> data;

	//Construcotr for the table
	public ProductTable() 
	{
		data = new ArrayList<Product>();
	}

	//Sets the arraylist of products
	public void setProducts(ArrayList<Product> products) 
	{
		data = products;
		fireTableDataChanged();
	}
	
	//Sets Gearboxes
	public void setGearbox(ArrayList<Gearbox> gearbox)
	{
		data = new ArrayList<Product>();
		data.addAll(gearbox);
		fireTableDataChanged();
	}
	
	//Sets Tires
	public void setTire(ArrayList<Tire> tire)
	{
		data = new ArrayList<Product>();
		data.addAll(tire);
		fireTableDataChanged();
	}
	
	//Sets Glass
	public void setGlass(ArrayList<Glass> glass)
	{
		data = new ArrayList<Product>();
		data.addAll(glass);
		fireTableDataChanged();
	}
		
	//Sets Tires
	public void setBrakeDisc(ArrayList<BrakeDisc> brakedisc)
	{
		data = new ArrayList<Product>();
		data.addAll(brakedisc);
		fireTableDataChanged();
	}
	
	//Sets lights
	public void setHeadligth(ArrayList<Headlights> headlights)
	{
		data = new ArrayList<Product>();
		data.addAll(headlights);
		fireTableDataChanged();
	}

	//Method does so table cannot be edited
	public boolean isCellEditable(int row, int col)
	{
		return false;
	}

	//Returns the column count
	@Override
	public int getColumnCount() 
	{
		return columnNames.length;
	}

	//Returns the row count
	@Override
	public int getRowCount() 
	{
		return data.size();
	}

	//Returns the column name
	@Override
	public String getColumnName(int col) 
	{
		return columnNames[col];
	}

	//Returns the product attributs to the table
	@Override
	public Object getValueAt(int row, int col) 
	{

		Product product = data.get(row);

		if (product.getClass().equals(Gearbox.class)) {
		switch (col) {

		case 0:
			return product.getProductNumber();
		case 1:
			return product.getSerialNumber();
		case 2:
			return product.getSupplier();
		case 3:
			return product.getProductName();
		case 4:
			return product.getPurchasePrice();
		case 5:
			return product.getSalesPrice();
		case 6:
			return product.getRentPrice();
		case 7:
			return product.getCountryOfOrigin();
		case 8:
			return product.getFabricant();
		case 9:
			return product.getDescription();
		case 10:
			return product.getCarModel();
		case 11:
			return product.getModelYear();
		case 12:
			return product.getMinStock();
		case 13:
			return product.getMaxStock();
		case 14:
			return ((Gearbox) product).getGearboxType();
		case 15: 
			return ((Gearbox) product).getGearAmount();
		case 16:
			return null;
		case 17:
			return null;
		case 18:
			return null;
		case 19:
			return null;
		case 20:
			return null;
		case 21:
			return null;
		case 22:
			return null;
		case 23:
			return ((Gearbox) product).getProductType();
		default:
			return null;

		}
		}
		
		if (product.getClass().equals(Tire.class)) {
			switch (col) {

			case 0:
				return product.getProductNumber();
			case 1:
				return product.getSerialNumber();
			case 2:
				return product.getSupplier();
			case 3:
				return product.getProductName();
			case 4:
				return product.getPurchasePrice();
			case 5:
				return product.getSalesPrice();
			case 6:
				return product.getRentPrice();
			case 7:
				return product.getCountryOfOrigin();
			case 8:
				return product.getFabricant();
			case 9:
				return product.getDescription();
			case 10:
				return product.getCarModel();
			case 11:
				return product.getModelYear();
			case 12:
				return product.getMinStock();
			case 13:
				return product.getMaxStock();
			case 14:
				return null;
			case 15: 
				return null;
			case 16: 
				return ((Tire) product).getTireType();
			case 17:
				return ((Tire) product).getTireSize();
			case 18:
				return null;
			case 19:
				return null;
			case 20:
				return null;
			case 21:
				return null;
			case 22:
				return null;
			case 23:
				return ((Tire) product).getProductType();
			default:
				return null;

			}
		}
			
			if (product.getClass().equals(Glass.class)) {
				switch (col) {

				case 0:
					return product.getProductNumber();
				case 1:
					return product.getSerialNumber();
				case 2:
					return product.getSupplier();
				case 3:
					return product.getProductName();
				case 4:
					return product.getPurchasePrice();
				case 5:
					return product.getSalesPrice();
				case 6:
					return product.getRentPrice();
				case 7:
					return product.getCountryOfOrigin();
				case 8:
					return product.getFabricant();
				case 9:
					return product.getDescription();
				case 10:
					return product.getCarModel();
				case 11:
					return product.getModelYear();
				case 12:
					return product.getMinStock();
				case 13:
					return product.getMaxStock();
				case 14:
					return null;
				case 15: 
					return null;
				case 16: 
					return null;
				case 17:
					return null;
				case 18:
					return ((Glass) product).getHeight();
				case 19:
					return ((Glass) product).getWidth();
				case 20:
					return ((Glass) product).getThickness();
				case 21:
					return null;
				case 22:
					return null;
				case 23:
					return ((Glass) product).getProductType();
				default:
					return null;
				}
			}
				
				if (product.getClass().equals(BrakeDisc.class)) {
					switch (col) {

					case 0:
						return product.getProductNumber();
					case 1:
						return product.getSerialNumber();
					case 2:
						return product.getSupplier();
					case 3:
						return product.getProductName();
					case 4:
						return product.getPurchasePrice();
					case 5:
						return product.getSalesPrice();
					case 6:
						return product.getRentPrice();
					case 7:
						return product.getCountryOfOrigin();
					case 8:
						return product.getFabricant();
					case 9:
						return product.getDescription();
					case 10:
						return product.getCarModel();
					case 11:
						return product.getModelYear();
					case 12:
						return product.getMinStock();
					case 13:
						return product.getMaxStock();
					case 14:
						return null;
					case 15: 
						return null;
					case 16: 
						return null;
					case 17:
						return null;
					case 18:
						return null;
					case 19:
						return null;
					case 20:
						return null;
					case 21:
						return ((BrakeDisc) product).getDiscType();
					case 22:
						return null;
					case 23:
						return ((BrakeDisc) product).getProductType();
					default:
						return null;
					}
				}
					
					if (product.getClass().equals(Headlights.class)) {
						switch (col) {

						case 0:
							return product.getProductNumber();
						case 1:
							return product.getSerialNumber();
						case 2:
							return product.getSupplier();
						case 3:
							return product.getProductName();
						case 4:
							return product.getPurchasePrice();
						case 5:
							return product.getSalesPrice();
						case 6:
							return product.getRentPrice();
						case 7:
							return product.getCountryOfOrigin();
						case 8:
							return product.getFabricant();
						case 9:
							return product.getDescription();
						case 10:
							return product.getCarModel();
						case 11:
							return product.getModelYear();
						case 12:
							return product.getMinStock();
						case 13:
							return product.getMaxStock();
						case 14:
							return null;
						case 15: 
							return null;
						case 16: 
							return null;
						case 17:
							return null;
						case 18:
							return null;
						case 19:
							return null;
						case 20:
							return null;
						case 21:
							return null;
						case 22:
							return ((Headlights) product).getLightsType();
						case 23:
							return ((Headlights) product).getProductType();
						default:
							return null;
						}		
		}
		return null;

	}

}
